var webpack = require('webpack')
const path = require("path");
let HtmlWebpackPlugin = require('html-webpack-plugin')
let enterFile;
if (process.env.NODE_ENV === 'production') {
  enterFile= './src/main.js'
} else {
  enterFile='./example/main.js'
}

module.exports = {
  entry: enterFile,
  output: {
    path: path.resolve(__dirname, './dist/'),
    publicPath: '',
    filename: 'main.js',
    library: 'VueFlagList',
    libraryTarget: 'umd',
    umdNamedDefine: true
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      },
      {
        test: /\.less$/,
        loaders: [
            {
                loader: 'style-loader',
                options: {
                    sourceMap: true,
                },
            },
            {
                loader: 'css-loader',
                options: {
                    sourceMap: true,
                },
            },
            {
                loader: 'less-loader',
                options: {
                    sourceMap: true,
                },
            },
        ]
      },
      {
        test: /\.(svg|ttf|eot|woff|woff2)$/,
        use: {
            loader: 'file-loader',
       }
      }
    ]
  },
  resolve: {
    extensions: ['*', '.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '~': path.join(__dirname,'./'),
    }
  },
  // externals: {
  //   vue: {
  //     root: 'Vue',
  //     commonjs: 'vue',
  //     commonjs2: 'vue',
  //     amd: 'vue'
  //   }
  // },
  devServer: {
    compress: true,
    port: 3031,
    contentBase: './example',
    hot: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
};

module.exports.plugins = (module.exports.plugins || []).concat([
  new webpack.HotModuleReplacementPlugin(),
  new HtmlWebpackPlugin({
    filename:'index.html',
    template: path.join(__dirname, './example/index.html')
  })
])
